package cn.edu.dgut.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 检查是否携带token参数
 */

@WebFilter("/login/dgut")
public class dgutFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletResponse response = (HttpServletResponse) resp;
        String token = req.getParameter("token");

        if(token==null){
            response.sendRedirect("https://cas.dgut.edu.cn?appid=javaee&state=STATE");
        }else{
            //有token则放行
            chain.doFilter(req, resp);
        }
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
